package chapters18;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by xinxuchu on 2020/2/5.
 * Timer固定延时示例
 */
public class TimerFixDelay {

    static class LongRunningTask extends TimerTask{

        @Override
        public void run(){
            try {
                Thread.sleep(5000);
            }catch (InterruptedException e){

            }
            System.out.println("long running finished!");
        }
    }

    static class FixedDelayTask extends TimerTask{

        @Override
        public void run(){
            System.out.println(System.currentTimeMillis());//时间long类型的数据
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Timer timer = new Timer();
        timer.schedule(new LongRunningTask(),10);
        timer.schedule(new FixedDelayTask(),100,1000);
    }
}
